using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

public class ScoreManager : MonoBehaviour
{
    public static ScoreManager Instance { get; private set; }

    [SerializeField] private GameObject scorePrefab;
    [SerializeField] private Sprite[] score3000;
    [SerializeField] private Sprite[] score5000;
    [SerializeField] private Sprite[] score10000;

    private Dictionary<int, Sprite[]> scoreDict;
    
    private void Awake()
    {
        Instance = this;
    }

    private void Start()
    {
        scoreDict = new Dictionary<int, Sprite[]>();
        scoreDict.Add(3000, score3000);
        scoreDict.Add(5000, score5000);
        scoreDict.Add(10000, score10000);
    }

    public void ShowScore(Vector3 position, int score)
    {
        GameObject scoreGo = GameObject.Instantiate(scorePrefab, position, Quaternion.identity);

        Sprite[] scpreArray;
        scoreDict.TryGetValue(score, out scpreArray);

        int index = Random.Range(0, scpreArray.Length);
        Sprite sprite = scpreArray[index];

        scoreGo.GetComponent<SpriteRenderer>().sprite = sprite;
        
        Destroy(scoreGo, 1f);
    }
}
